﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;

namespace Core.Unity.Wpf {
    public class ContainerWpf : IXContainer {
        private Dictionary<string, object> _pool = new Dictionary<string, object>();

        public Dictionary<string, object> Pool {
            get {
                return _pool;
            }
        }

        private IUnityContainer _prismContainer;

        public ContainerWpf(IUnityContainer prismContainer) {
            _prismContainer = prismContainer;
        }

        public new void Register<I>(I instance) {
            _pool[typeof(I).FullName] = instance;
            _prismContainer.RegisterInstance<I>(instance);
        }

        public void RegisterInstance<I>(I instance) {
            _pool[typeof(I).FullName] = instance;
            _prismContainer.RegisterInstance<I>(instance);
        }

        public I Resolve<I>() {
            if (_pool.Keys.Contains(typeof(I).FullName)) {
                return (I)_pool[typeof(I).FullName];
            }
            return default(I);
        }

        public Dictionary<string, object> GetAll() {
            return _pool;
        }
    }
}
